#!/bin/bash

function umnt_wait()
{
    for i in {1..5}
    do
        # echo "umount $1 . #$i"
        umount $1
        sleep 1
        if [ ! -d $1 ]; then 
            return 0
        else
            if (( $(ls -a $1 | wc -l) == 2)); then
                return 0
            fi
        fi
    done
    return 1
}

for path in $(ls -d fs_debian_* 2> /dev/null);
do
    umnt_wait $path/proc
    umnt_wait $path/sys
    umnt_wait $path/dev/pts
    umnt_wait $path/customs
    if (( $? == 0 )); then 
        sudo rm -rf $path
    else
        echo -e "\033[1;33;41m E: 自定义操作文件夹卸载失败，操作无法进行。\033[0m"
    fi
done 
sudo rm -rf $(find . -name "*.tmp")
